home *** CD-ROM | disk | FTP | other *** search
- /*
- kbhit.c
- 6/13/90 dgp wrote it, based on suggestion from Michael Kahl and an earlier version by
- Evan Relkin.
- 2/16/93 dgp added YesOrNo().
- */
- #ifndef THINK_C
- #error "Sorry, kbhit.c requires THINK C."
- #endif
- #include "VideoToolbox.h"
- #include <console.h>
-
- int kbhit(void)
- {
- int c;
-
- c = getcharUnbuffered();
- if (c == EOF) return 0;
- ungetc(c, stdin);
- return 1;
- }
-
- int getcharUnbuffered(void)
- {
- int c;
-
- csetmode(C_RAW,stdin); /* unbuffered, no echo, no editing */
- c = getchar();
- csetmode(C_ECHO,stdin); /* default mode: line-buffered, echo, full editing */
- return c;
- }
-
- // Accept one character yes/no answer and spell out "Yes" or "No"
- Boolean YesOrNo(Boolean defaultAnswer)
- {
- char c;
- Boolean answer;
-
- if(defaultAnswer)printf(" (Yes):");
- else printf(" (No):");
- fflush(stdout);
- do{
- c=getcharUnbuffered();
- }while(c==-1);
- if(c==14)abort(); // Crude test for command-period.
- if(defaultAnswer)answer=!(tolower(c)=='n'); // Anything but 'n' or 'N' means yes
- else answer=(tolower(c)=='y'); // Anything but 'y' or 'Y' means no
- if(answer)printf("Yes.");
- else printf("No.");
- return answer;
- }
-